var e = require;
var t = module;
var o = exports;
var ii, nn = this && this.__extends || (ii = function (t, e) {
    return (ii = Object.setPrototypeOf || {
        __proto__: []
    }
        instanceof Array &&
        function (t, e) {
            t.__proto__ = e
        } ||
        function (t, e) {
            for (var o in e) Object.prototype.hasOwnProperty.call(e, o) && (t[o] = e[o])
        })(t, e)
},
    function (t, e) {
        function o() {
            this.constructor = t
        }
        ii(t, e),
            t.prototype = null === e ? Object.create(e) : (o.prototype = e.prototype, new o)
    }
),
    rr = this && this.__awaiter ||
        function (t, e, o, i) {
            return new (o || (o = Promise))(function (n, a) {
                function r(t) {
                    try {
                        l(i.next(t))
                    } catch (e) {
                        a(e)
                    }
                }
                function s(t) {
                    try {
                        l(i.
                            throw(t))
                    } catch (e) {
                        a(e)
                    }
                }
                function l(t) {
                    var e;
                    t.done ? n(t.value) : (e = t.value, e instanceof o ? e : new o(function (t) {
                        t(e)
                    })).then(r, s)
                }
                l((i = i.apply(t, e || [])).next())
            })
        };
var oo = (this && this.__decorate) ||
    function (e, t, a, n) {
        var i,
            o = arguments.length,
            s = o < 3 ? t : null === n ? (n = Object.getOwnPropertyDescriptor(t, a)) : n;
        if ("object" == typeof Reflect && "function" == typeof Reflect.decorate) s = Reflect.decorate(e, t, a, n);
        else
            for (var r = e.length - 1; r >= 0; r--)
                (i = e[r]) && (s = (o < 3 ? i(s) : o > 3 ? i(t, a, s) : i(t, a)) || s);
        return o > 3 && s && Object.defineProperty(t, a, s), s;
    };
Object.defineProperty(o, "__esModule", { value: !0 });
var a = e("BaseModuleUI"),
    n = e("NotifyEventType"),
    i = e("GlobalParams"),
    r = e("AssetsManager"),
    s = e("PureHelper"),
    l = e("RoleSoldierInfo"),
    _ = e("sdkConfig"),
    c = e("AD"),
    d = cc._decorator,
    h = d.ccclass,
    u = d.property,
    p = (function (e) {
        function t() {
            var t = (null !== e && e.apply(this, arguments)) || this;
            return (
                (t.touch_node = null),
                (t.touch_bg = null),
                (t.touch_bar = null),
                (t.use_skill_list = []),
                (t.attack_node = null),
                (t.skill_one_node = null),
                (t.skill_two_node = null),
                (t.skill_one_cooling_label = null),
                (t.skill_two_cooling_label = null),
                (t.operate_hero_btn = []),
                (t.operate_hero_head = []),
                (t.skill_one_btn = null),
                (t.skill_two_btn = null),
                (t.native_icon_node = null),
                (t.left_move = !1),
                (t.right_move = !1),
                (t.up_move = !1),
                (t.down_move = !1),
                (t.one_skill_cooling = !1),
                (t.two_skill_cooling = !1),
                (t.operate_hero = [1, 2]),
                (t.is_PC = !1),
                t
            );
        }
        return (
            nn(t, e),
            (t.prototype.initView = function () {
                (this.native_icon_node.active =
                    _.default.platform != _.EPlatform.NO_AD && !c.default.getInstance().getGameTestVersion()),
                    navigator.userAgent.match(/(iPhone|iPAD|Android|ios)/i)
                        ? ((this.touch_node.active = !0), (this.is_PC = !1))
                        : ((this.touch_node.active = !1), (this.is_PC = !0)),
                    this.attack_node.addComponent(cc.Button),
                    this.skill_one_node.addComponent(cc.Button),
                    this.skill_two_node.addComponent(cc.Button),
                    (this.attack_node.getComponent(cc.Button).transition = cc.Button.Transition.SCALE),
                    (this.attack_node.getComponent(cc.Button).zoomScale = 0.9),
                    (this.skill_one_node.getComponent(cc.Button).transition = cc.Button.Transition.SCALE),
                    (this.skill_one_node.getComponent(cc.Button).zoomScale = 0.9),
                    (this.skill_two_node.getComponent(cc.Button).transition = cc.Button.Transition.SCALE),
                    (this.skill_two_node.getComponent(cc.Button).zoomScale = 0.9),
                    this.showHeroSkillInfo(),
                    this.showOperateHeroInfo();
            }),
            (t.prototype.addEvent = function () {
                this.touch_node.on(cc.Node.EventType.TOUCH_START, this.TouchStart, this),
                    this.touch_node.on(cc.Node.EventType.TOUCH_MOVE, this.TouchMove, this),
                    this.touch_node.on(cc.Node.EventType.TOUCH_END, this.TouchEnd, this),
                    this.touch_node.on(cc.Node.EventType.TOUCH_CANCEL, this.TouchEnd, this),
                    this.attack_node.on("click", this.playerAttack, this),
                    this.skill_one_node.on("click", this.playerSkillOne, this),
                    this.skill_two_node.on("click", this.playerSkillTwo, this),
                    cc.systemEvent.on(cc.SystemEvent.EventType.KEY_DOWN, this.onKeyDown, this),
                    cc.systemEvent.on(cc.SystemEvent.EventType.KEY_UP, this.onKeyUp, this),
                    this.attachEvent(n.default.SEND_PLAYER_CHOOSE_OPERATE_HERO_INDEX, this.updateOperate, this),
                    this.attachEvent(n.default.SEND_PLAYER_SKILL_COOLING_TIME, this.showCoolingTime, this),
                    this.attachEvent(n.default.SEND_ROLE_BE_KILL_INFO, this.showHeroDieInfo, this),
                    this.attachEvent(n.default.SEND_D_GAME_TOUCH_OPERATE_INFO, this.showReviveHero, this);
            }),
            (t.prototype.OnClick = function (t) {
                switch ((e.prototype.OnClick.call(this, t), t.node.name)) {
                    case "operate_hero_one":
                        this.chooseOperateInfo(0);
                        break;
                    case "operate_hero_two":
                        this.chooseOperateInfo(1);
                }
            }),
            (t.prototype.onKeyDown = function (e) {
                switch (e.keyCode) {
                    case cc.macro.KEY.d:
                        this.right_move = !0;
                        break;
                    case cc.macro.KEY.a:
                        this.left_move = !0;
                        break;
                    case cc.macro.KEY.w:
                        this.up_move = !0;
                        break;
                    case cc.macro.KEY.s:
                        this.down_move = !0;
                }
            }),
            (t.prototype.onKeyUp = function (e) {
                switch (e.keyCode) {
                    case cc.macro.KEY.j:
                        this.emitEvent(n.default.SEND_PLAYER_FREE_SKILL);
                        break;
                    case cc.macro.KEY.k:
                        this.emitEvent(n.default.SEND_PLAYER_FREE_SKILL_ONE);
                        break;
                    case cc.macro.KEY.l:
                        this.emitEvent(n.default.SEND_PLAYER_FREE_SKILL_TWO);
                        break;
                    case cc.macro.KEY.d:
                        this.right_move = !1;
                        break;
                    case cc.macro.KEY.a:
                        this.left_move = !1;
                        break;
                    case cc.macro.KEY.w:
                        this.up_move = !1;
                        break;
                    case cc.macro.KEY.s:
                        this.down_move = !1;
                        break;
                    case cc.macro.KEY.i:
                        this.chooseOperateInfo(0);
                        break;
                    case cc.macro.KEY.o:
                        this.chooseOperateInfo(1);
                }
            }),
            (t.prototype.update = function () {
                if (this.is_PC && i.GlobalParams.GameStart) {
                    var e = cc.v2(0, 0);
                    this.right_move && (e.x = 1),
                        this.left_move && (e.x = -1),
                        this.up_move && (e.y = 1),
                        this.down_move && (e.y = -1),
                        0 == e.x && 0 == e.y
                            ? this.emitEvent(n.default.SEND_PLAYER_STOP_MOVE_INFO)
                            : this.emitEvent(n.default.SEND_PLAYER_MOVE_INFO, e);
                }
            }),
            (t.prototype.playerAttack = function () {
                i.GlobalParams.GameStart && this.emitEvent(n.default.SEND_PLAYER_FREE_SKILL);
            }),
            (t.prototype.playerSkillOne = function () {
                i.GlobalParams.GameStart &&
                    (this.emitEvent(n.default.SEND_PLAYER_FREE_SKILL_ONE),
                        this.skill_one_node.getChildByName("cooling").active ||
                        ((this.use_skill_list[0].node.active = !0),
                            this.use_skill_list[0].setAnimation(0, "animation", !0)));
            }),
            (t.prototype.playerSkillTwo = function () {
                i.GlobalParams.GameStart &&
                    (this.emitEvent(n.default.SEND_PLAYER_FREE_SKILL_TWO),
                        this.skill_two_node.getChildByName("cooling").active ||
                        ((this.use_skill_list[1].node.active = !0),
                            this.use_skill_list[1].setAnimation(0, "animation", !0)));
            }),
            (t.prototype.showCoolingTime = function (e, t) {
                var o = Number(t.time.toFixed(1));
                1 == t.type
                    ? ((this.one_skill_cooling = !0),
                        (this.skill_one_cooling_label.node.parent.active = !0),
                        (this.skill_one_btn.getChildByName("use_skill").active = !1),
                        this.btnCoolingInfo(this.skill_one_cooling_label, o, o, 1))
                    : 2 == t.type &&
                    ((this.two_skill_cooling = !0),
                        (this.skill_two_cooling_label.node.parent.active = !0),
                        (this.skill_two_btn.getChildByName("use_skill").active = !1),
                        this.btnCoolingInfo(this.skill_two_cooling_label, o, o, 2));
            }),
            (t.prototype.btnCoolingInfo = function (e, t, o, a) {
                var n = this;
                ((1 == a && !this.one_skill_cooling) || (2 == a && !this.two_skill_cooling)) && (t = 0);
                var i = e.node.parent.getChildByName("bg").getComponent(cc.Sprite);
                t <= 0
                    ? ((i.fillRange = 1),
                        (e.node.parent.active = !1),
                        1 == a ? (this.one_skill_cooling = !1) : (this.two_skill_cooling = !1))
                    : ((t = Number(t.toFixed(1))),
                        (e.string = "" + t),
                        cc
                            .tween(i)
                            .to(1, { fillRange: t / o })
                            .call(function () {
                                t--, n.btnCoolingInfo(e, t, o, a);
                            })
                            .start());
            }),
            (t.prototype.chooseOperateInfo = function (e) {
                if (
                    !this.operate_hero_btn[e].getChildByName("hero_die").active &&
                    !this.operate_hero_btn[e].getChildByName("cooling").active
                ) {
                    this.emitEvent(n.default.SEND_PLAYER_STOP_MOVE_INFO);
                    var t = i.GlobalParams.MatchMyIndex;
                    (i.GlobalParams.MatchMyIndex = this.operate_hero[e]),
                        (this.operate_hero[e] = t),
                        this.showOperateHeroInfo(),
                        this.emitEvent(n.default.SEND_PLAYER_CHOOSE_OPERATE_HERO_INDEX),
                        this.usePlayerSkill(e);
                }
            }),
            (t.prototype.TouchStart = function (e) {
                var t = e.touch.getLocation();
                (t = this.touch_node.convertToNodeSpaceAR(t)), this.touch_bg.setPosition(t);
            }),
            (t.prototype.TouchMove = function (e) {
                var t = e.touch.getLocation();
                (t = this.touch_bg.convertToNodeSpaceAR(t)),
                    Math.abs(s.default.Distance(t, cc.v2(0, 0))) > 100 &&
                    (t = s.default.getTailPosOuter(t, cc.v2(0, 0), -100)),
                    this.touch_bar.setPosition(t);
                var o = cc.v2(t.x, t.y).sub(cc.v2(0, 0)).normalize();
                this.emitEvent(n.default.SEND_PLAYER_MOVE_INFO, o);
            }),
            (t.prototype.TouchEnd = function () {
                this.touch_bar.setPosition(cc.v2(0, 0)),
                    this.emitEvent(n.default.SEND_PLAYER_STOP_MOVE_INFO),
                    this.touch_bg.setPosition(cc.v2(-80, -20));
            }),
            (t.prototype.usePlayerSkill = function (e) {
                var t = this.operate_hero_btn[e].getChildByName("cooling");
                if (!t.active) {
                    t.active = !0;
                    var o = 10;
                    2 == i.GlobalParams.ChangeGameMode && (o /= 2), this.playerSkillCooling(t, o, o);
                }
            }),
            (t.prototype.playerSkillCooling = function (e, t, o) {
                var a = this;
                if (t <= 0) e.active = !1;
                else {
                    e.getChildByName("cooling_num").getComponent(cc.Label).string = "" + t;
                    var n = e.getChildByName("bg").getComponent(cc.Sprite);
                    cc.tween(n)
                        .to(1, { fillRange: t / o })
                        .call(function () {
                            t--, a.playerSkillCooling(e, t, o);
                        })
                        .start();
                }
            }),
            (t.prototype.updateOperate = function () {
                this.showHeroSkillInfo();
            }),
            (t.prototype.showHeroSkillInfo = function () {
                var e = i.GlobalParams.MatchGamePlayer[i.GlobalParams.MatchMyIndex];
                (this.skill_one_btn.getChildByName("skill_icon").getComponent(cc.Sprite).spriteFrame = r.default
                    .getInstance()
                    .getHeroSkilIcon("skill_" + l.default.Role_info[e.role_id].id + "01")),
                    (this.skill_two_btn.getChildByName("skill_icon").getComponent(cc.Sprite).spriteFrame = r.default
                        .getInstance()
                        .getHeroSkilIcon("skill_" + l.default.Role_info[e.role_id].id + "02")),
                    (this.skill_one_btn.getChildByName("skill_des").getComponent(cc.Label).string =
                        l.default.Role_info[e.role_id].S1_des),
                    (this.skill_two_btn.getChildByName("skill_des").getComponent(cc.Label).string =
                        l.default.Role_info[e.role_id].S2_des),
                    (this.skill_one_btn.getChildByName("use_skill").active = !1),
                    (this.skill_two_btn.getChildByName("use_skill").active = !1),
                    (this.one_skill_cooling = !1),
                    (this.two_skill_cooling = !1);
            }),
            (t.prototype.showOperateHeroInfo = function () {
                for (var e = 0; e < 2; e++)
                    if (-1 != this.operate_hero[e]) {
                        var t = l.default.Role_info[i.GlobalParams.MatchGamePlayer[this.operate_hero[e]].role_id];
                        (this.operate_hero_head[e].spriteFrame = r.default
                            .getInstance()
                            .getGameHoreHeadFrame("hero_" + t.id)),
                            (this.operate_hero_btn[e].getChildByName("name").getComponent(cc.Label).string =
                                "" + t.C_Name);
                    }
                this.showOperateInfo();
            }),
            (t.prototype.showHeroDieInfo = function (e, t) {
                if (t.be_kill < 3) {
                    if (-1 == this.operate_hero[0] && -1 == this.operate_hero[1])
                        return (
                            (i.GlobalParams.GameStart = !1),
                            (i.GlobalParams.GamePlayerWin = !1),
                            void this.emitEvent(n.default.SEND_GAME_OVER_INFO)
                        );
                    var o = this.operate_hero.indexOf(t.be_kill);
                    if (-1 != o)
                        (this.operate_hero_btn[o].getChildByName("hero_die").active = !0),
                            (this.operate_hero_btn[o].getChildByName("name").active = !1),
                            (this.operate_hero[o] = -1);
                    else
                        for (var a = 0; a < 2; a++)
                            if (-1 != this.operate_hero[a]) {
                                this.chooseOperateInfo(a),
                                    (this.operate_hero_btn[a].getChildByName("hero_die").active = !0),
                                    (this.operate_hero_btn[a].getChildByName("name").active = !1),
                                    (this.operate_hero[a] = -1);
                                break;
                            }
                }
            }),
            (t.prototype.showReviveHero = function () {
                this.operate_hero = [];
                for (var e = 0; e < 3; e++) e != i.GlobalParams.MatchMyIndex && this.operate_hero.push(e);
                this.showOperateInfo();
            }),
            (t.prototype.showOperateInfo = function () {
                for (var e = 0; e < 2; e++)
                    (this.operate_hero_btn[e].getChildByName("hero_die").active = -1 == this.operate_hero[e]),
                        (this.operate_hero_btn[e].getChildByName("name").active = -1 != this.operate_hero[e]);
            }),
            oo([u(cc.Node)], t.prototype, "touch_node", void 0),
            oo([u(cc.Node)], t.prototype, "touch_bg", void 0),
            oo([u(cc.Node)], t.prototype, "touch_bar", void 0),
            oo([u(sp.Skeleton)], t.prototype, "use_skill_list", void 0),
            oo([u(cc.Node)], t.prototype, "attack_node", void 0),
            oo([u(cc.Node)], t.prototype, "skill_one_node", void 0),
            oo([u(cc.Node)], t.prototype, "skill_two_node", void 0),
            oo([u(cc.Label)], t.prototype, "skill_one_cooling_label", void 0),
            oo([u(cc.Label)], t.prototype, "skill_two_cooling_label", void 0),
            oo([u(cc.Node)], t.prototype, "operate_hero_btn", void 0),
            oo([u(cc.Sprite)], t.prototype, "operate_hero_head", void 0),
            oo([u(cc.Node)], t.prototype, "skill_one_btn", void 0),
            oo([u(cc.Node)], t.prototype, "skill_two_btn", void 0),
            oo([u(cc.Node)], t.prototype, "native_icon_node", void 0),
            oo([h], t)
        );
    })(a.default);
o.default = p;
